core: Use fd-relative creation for tmp/
authorColin Walters <walters@verbum.org>
Fri, 6 Sep 2013 22:19:54 +0000 (18:19 -0400)
committerColin Walters <walters@verbum.org>
Fri, 6 Sep 2013 22:45:16 +0000 (18:45 -0400)
Update libgsystem submodule for a bugfix.

This is both more efficient from a kernel perspective, and avoids us
calling gs_file_get_path_cached() on tmp_dir constantly, which
triggered another bug due to lack of locking.

src/libgsystem
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo.c

index 1c1a7c15029176928534d28fb1fb5f17adf7c776..d63409a3d44b61e40f30cde79ebae879925c716d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 1c1a7c15029176928534d28fb1fb5f17adf7c776
+Subproject commit d63409a3d44b61e40f30cde79ebae879925c716d
index e03656d6aa686b319daba6a58b0ba674fabe6df4..10953b32340dd650a5acd7f27a9a852df42a1db4 100644 (file)
@@ -29,6 +29,7 @@ struct OstreeRepo {
 
   GFile *repodir;
   GFile *tmp_dir;
+  int    tmp_dir_fd;
   GFile *pending_dir;
   GFile *local_heads_dir;
   GFile *remote_heads_dir;
index 814babeb72cec750ac9beeec6cf7650f2b820d08..aaee9a1fe74fce8c552b579f4be93bc3a3646382 100644 (file)
@@ -97,6 +97,8 @@ ostree_repo_finalize (GObject *object)
 
   g_clear_object (&self->repodir);
   g_clear_object (&self->tmp_dir);
+  if (self->tmp_dir_fd)
+    (void) close (self->tmp_dir_fd);
   g_clear_object (&self->pending_dir);
   g_clear_object (&self->local_heads_dir);
   g_clear_object (&self->remote_heads_dir);
@@ -528,6 +530,9 @@ ostree_repo_open (OstreeRepo    *self,
                                             TRUE, &self->enable_uncompressed_cache, error))
     goto out;
 
+  if (!gs_file_open_dir_fd (self->tmp_dir, &self->tmp_dir_fd, cancellable, error))
+    goto out;
+
   self->inited = TRUE;
   
   ret = TRUE;
@@ -719,6 +724,7 @@ stage_object (OstreeRepo         *self,
   const char *actual_checksum;
   gboolean do_commit;
   OstreeRepoMode repo_mode;
+  gs_free char *temp_filename = NULL;
   gs_unref_object GFile *temp_file = NULL;
   gs_unref_object GFile *raw_temp_file = NULL;
   gs_unref_object GFile *stored_path = NULL;
@@ -783,9 +789,10 @@ stage_object (OstreeRepo         *self,
       if (repo_mode == OSTREE_REPO_MODE_BARE && temp_file_is_regular)
         {
           gs_unref_object GOutputStream *temp_out = NULL;
-          if (!gs_file_open_in_tmpdir (self->tmp_dir, 0644, &temp_file, &temp_out,
-                                       cancellable, error))
+          if (!gs_file_open_in_tmpdir_at (self->tmp_dir_fd, 0644, &temp_filename, &temp_out,
+                                          cancellable, error))
             goto out;
+          temp_file = g_file_get_child (self->tmp_dir, temp_filename);
           if (g_output_stream_splice (temp_out, file_input, G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
                                       cancellable, error) < 0)
             goto out;
@@ -805,10 +812,11 @@ stage_object (OstreeRepo         *self,
           gs_unref_object GConverter *zlib_compressor = NULL;
           gs_unref_object GOutputStream *compressed_out_stream = NULL;
 
-          if (!gs_file_open_in_tmpdir (self->tmp_dir, 0644,
-                                       &temp_file, &temp_out,
-                                       cancellable, error))
+          if (!gs_file_open_in_tmpdir_at (self->tmp_dir_fd, 0644,
+                                          &temp_filename, &temp_out,
+                                          cancellable, error))
             goto out;
+          temp_file = g_file_get_child (self->tmp_dir, temp_filename);
           temp_file_is_regular = TRUE;
 
           file_meta = _ostree_zlib_file_header_new (file_info, xattrs);
@@ -837,9 +845,10 @@ stage_object (OstreeRepo         *self,
   else
     {
       gs_unref_object GOutputStream *temp_out = NULL;
-      if (!gs_file_open_in_tmpdir (self->tmp_dir, 0644, &temp_file, &temp_out,
-                                   cancellable, error))
+      if (!gs_file_open_in_tmpdir_at (self->tmp_dir_fd, 0644, &temp_filename, &temp_out,
+                                      cancellable, error))
         goto out;
+      temp_file = g_file_get_child (self->tmp_dir, temp_filename);
       if (g_output_stream_splice (temp_out, checksum_input ? (GInputStream*)checksum_input : input,
                                   G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
                                   cancellable, error) < 0)